/**
 * @author 
 * @createtime 
 * @class ProjectRegisterForm
 * @extends Ext.Window
 * @description ProjectRegister表单
 */
ProjectRegisterForm=Ext.extend(Ext.Window,{
	//内嵌FormPanel
	formPanel:null,
	//构造函数
	constructor:function(_cfg){
		Ext.applyIf(this,_cfg);
		//必须先初始化组件
		this.initUIComponents();
		ProjectRegisterForm.superclass.constructor.call(this,{
			id:'ProjectRegisterFormWin',
			layout:'fit',
			items:this.formPanel,
			modal:true,
			height:500,
			width:600,
			maximizable:true,
			title:'[项目立项登记]详细信息',
			buttonAlign : 'center',
			buttons:this.buttons
		});
	},//end of the constructor
	//初始化组件
	initUIComponents:function(){
		this.formPanel = new Ext.FormPanel({
							layout : 'form',
							trackResetOnLoad : true,
							bodyStyle : 'padding:10px 10px 10px 10px',
							border : false,
							autoScroll : true,
			    			bodyStyle: 'padding:10px 10px 10px 10px;overflow-x:hidden;overflow-y:scroll',
							url : __ctxPath
									+ '/project/saveProjectRegister.do',
							id : 'ProjectRegisterForm',
							defaults : {
								anchor : '98%,98%'
							},
							defaultType : 'textfield',
							items : [{
										name : 'projectRegister.id',
										id : 'id',
										xtype : 'hidden',
										value : this.id == null ? '' : this.id
									},{
										name : 'projectRegister.status',
										id : 'status',
										xtype : 'hidden'
									},{
										name : 'projectRegister.proRegisterTitle',
										id : 'proRegisterTitle',
										xtype : 'hidden'
									}, {
										fieldLabel : '工程名称',
										allowBlank:false,
										maxLength:64,
										name : 'projectRegister.proName',
										id : 'proName'
									}, {
										fieldLabel : '业务员',
										name : 'businesserName',
										id : 'businesserName',
										emptyText:'请选择业务员',
										allowBlank:false,
										listeners:{
											focus:function(){
												UserSelector.getView(function(ids, names) {
														Ext.getCmp("businesserName").setValue(names);
														Ext.getCmp("projectRegister.businesser.userId").setValue(ids);
													}, true).show();
											}
										}
									},{
										xtype:'hidden',
										name:'projectRegister.businesser.userId',
									 	id:'projectRegister.businesser.userId'
									}, {
										fieldLabel : '业务来源',
										maxLength:64,
										allowBlank:false,
										name : 'projectRegister.businessSource',
										id : 'businessSource'
									}, {
										fieldLabel : '招标单位',
										maxLength:64,
										allowBlank:false,
										name : 'projectRegister.bidUnit',
										id : 'bidUnit'
									}, {
										fieldLabel : '项目属性',
										maxLength:64,
										allowBlank:false,
										name : 'projectRegister.props',
										id : 'props'
									}, {
										fieldLabel : '筹资属性',
										maxLength:64,
										allowBlank:false,
										name : 'projectRegister.moneyProps',
										id : 'moneyProps'
									}, {
										fieldLabel : '项目所在地',
										maxLength:64,
										allowBlank:false,
										name : 'projectRegister.proArea',
										id : 'proArea'
									}, {
										fieldLabel : '预计产值（万元）',
										allowBlank:false,
										name : 'projectRegister.preAmount',
										id : 'preAmount',
										xtype:'numberfield',
										maxLength:9,
										regex:/^(([1-9]\d{0,9})|0)(\.\d{1,2})?$/
									}, {
										fieldLabel : '预计工期开始',
										allowBlank:false,
										name : 'projectRegister.preDuration',
										id : 'preDuration',
										xtype:'datefield',
										format:'Y-m-d'
									}, {
										fieldLabel : '预计工期结束',
										allowBlank:false,
										name : 'projectRegister.preDurationEnd',
										id : 'preDurationEnd',
										xtype:'datefield',
										format:'Y-m-d'
									}, {
										fieldLabel : '质量要求',
										maxLength:64,
										allowBlank:false,
										name : 'projectRegister.quality',
										id : 'quality'
									}, {
										fieldLabel : '使用面积（平方）',
										maxLength:64,
										allowBlank:false,
										name : 'projectRegister.useArea',
										id : 'useArea'
									}, {
										fieldLabel : '招标方式',
										maxLength:64,
										allowBlank:false,
										name : 'projectRegister.bidType',
										id : 'bidType'
									}, {
										fieldLabel : '人脉关系',
										maxLength:64,
										allowBlank:false,
										name : 'projectRegister.humanRelations',
										id : 'humanRelations'
									}, {
										fieldLabel : '中标几率',
										maxLength:64,
										allowBlank:false,
										name : 'projectRegister.winBidProbability',
										id : 'winBidProbability'
									}, {
										fieldLabel : '技术标编制人',
										name : 'techBidMakerName',
										id : 'techBidMakerName',
										emptyText:'请选择技术标编制人',
										allowBlank:false,
										listeners:{
											focus:function(){
												UserSelector.getView(function(ids, names) {
														Ext.getCmp("techBidMakerName").setValue(names);
														Ext.getCmp("projectRegister.techBidMaker.userId").setValue(ids);
													}, true).show();
											}
										}
									},{
										xtype:'hidden',
										name:'projectRegister.techBidMaker.userId',
									 	id:'projectRegister.techBidMaker.userId'
									}, {
										fieldLabel : '经济标编制人',
										name : 'economicBidMakerName',
										id : 'economicBidMakerName',
										emptyText:'请选择经济标编制人',
										allowBlank:false,
										listeners:{
											focus:function(){
												UserSelector.getView(function(ids, names) {
														Ext.getCmp("economicBidMakerName").setValue(names);
														Ext.getCmp("projectRegister.economicBidMaker.userId").setValue(ids);
													}, true).show();
											}
										}
									},{
										xtype:'hidden',
										name:'projectRegister.economicBidMaker.userId',
									 	id:'projectRegister.economicBidMaker.userId'
									}, {
										fieldLabel : '投标截止日期',
										name : 'projectRegister.endBidDate',
										id : 'endBidDate',
										xtype:'datefield',
										allowBlank:false,
										format:'Y-m-d'
									}, {
										fieldLabel : '投标保证金(元)',
										name : 'projectRegister.bidDeposit',
										id : 'bidDeposit',
										xtype:'numberfield',
										maxLength:9,
										regex:/^(([1-9]\d{0,9})|0)(\.\d{1,2})?$/,
										regexText:'请输入正确格式的金额'
									}, {
										fieldLabel : '登记日期',
										name : 'projectRegister.registDate',
										id : 'registDate',
										xtype:'datefield',
										allowBlank:false,
										format:'Y-m-d'
									}, {
										fieldLabel : '备注',
										name : 'projectRegister.remark',
										id : 'remark',
										xtype:'textarea'
									},{
										xtype : 'container',
										autoHeight : true,
										layout : 'column',
										autoWidth : true,
										defaultType : 'label',
										style : 'padding-left:0px;padding-bottom:5px;',
										items : [{
													text : '附件:',
													width:95,
													style : "margin-top:15px;"
												},{
													xtype : 'hidden',
													name : 'attachIds',
													id : 'projectRegister.attachIds'
												},{
													xtype : 'hidden',
													name : 'attachFiles',
													id : 'projectRegister.attachFiles'
												},{
													xtype : 'panel',
													id:'projectRegister.displayAttach',
													columnWidth:.95,
													height: 65,
													frame:false,
													autoScroll:true,
													style : 'padding-left:10px;padding-top:0px;',
													html : ''
												},{
													xtype : 'button',
													iconCls : 'btn-upload',
													text : '上传',
													handler : function() {
														var dialog = App.createUploadDialog({
																				file_cat : 'flow/projectRegister',
																				callback : function(data) {
																					Ext.getCmp('projectRegister.displayAttach').body.update('');
																					Ext.getCmp("projectRegister.attachFiles").setValue('');
																					Ext.getCmp('projectRegister.attachIds').setValue('');
																					var attachFiles = Ext.getCmp("projectRegister.attachFiles");
																					var fileIds = Ext.getCmp('projectRegister.attachIds');
																					var display = Ext.getCmp('projectRegister.displayAttach');
																					for (var i = 0; i < data.length; i++) {
																						if (fileIds.getValue() != '') {
																							fileIds.setValue(fileIds.getValue()+ ',');
																							attachFiles.setValue(attachFiles.getValue()+ ',');
																						}
																						attachFiles.setValue(attachFiles.getValue()+data[i].filepath+":"+data[i].filename.replace(/\s+/g,""));
																						fileIds.setValue(fileIds.getValue()+data[i].fileId);
																						Ext.DomHelper.append(display.body,'<span><a href="#" onclick="FileAttachDetail.show('+data[i].fileId+')">'+data[i].filename.replace(/\s+/g,"")+'</a>&nbsp;|&nbsp;</span>');
																					}
																				},
																				permitted_max_size :1024*1024*20
																			});
															dialog.show(this);
													}
												}]
									}
							]
						});
		// 加载表单对应的数据
		this.initData();
		// 初始化功能按钮
		this.buttons=[{
				text : '保存',
				iconCls : 'btn-save',
				handler :this.save.createCallback(this.formPanel,this)
			}, {
				text : '重置',
				iconCls : 'btn-reset',
				handler :this.reset.createCallback(this.formPanel)
			},{
				text : '取消',
				iconCls : 'btn-cancel',
				handler : this.cancel.createCallback(this)
			}];
	},// end of the initcomponents
	/**
	 * 初始化数据
	 * 
	 * @param {}
	 *            formPanel
	 */
	initData:function(){
		// 加载表单对应的数据
		if (this.id != null && this.id != 'undefined') {
			this.formPanel.getForm().load({
				deferredRender : false,
				url : __ctxPath + '/project/getProjectRegister.do?id='+ this.id,
				waitMsg : '正在载入数据...',
				success : function(form, action) {
						var jsonData = Ext.util.JSON.decode(action.response.responseText);
						var res = jsonData.data;
						//Ext.getCmp("").originalValue=
						if(!Ext.isEmpty(res.businesser)){
							Ext.getCmp("projectRegister.businesser.userId").setValue(res.businesser.userId);
							Ext.getCmp("projectRegister.businesser.userId").originalValue=res.businesser.userId;
							Ext.getCmp("businesserName").setValue(res.businesser.fullname);
							Ext.getCmp("businesserName").originalValue=res.businesser.fullname;
						}
						if(!Ext.isEmpty(res.techBidMaker)){
							Ext.getCmp("projectRegister.techBidMaker.userId").setValue(res.techBidMaker.userId);
							Ext.getCmp("projectRegister.techBidMaker.userId").originalValue=res.techBidMaker.userId;
							Ext.getCmp("techBidMakerName").setValue(res.techBidMaker.fullname);
							Ext.getCmp("techBidMakerName").originalValue=res.techBidMaker.fullname;
						}
						if(!Ext.isEmpty(res.economicBidMaker)){
							Ext.getCmp("projectRegister.economicBidMaker.userId").setValue(res.economicBidMaker.userId);
							Ext.getCmp("projectRegister.economicBidMaker.userId").originalValue=res.economicBidMaker.userId;
							Ext.getCmp("economicBidMakerName").setValue(res.economicBidMaker.fullname);
							Ext.getCmp("economicBidMakerName").originalValue=res.economicBidMaker.fullname;
						}
						var af = res.fileAttachs;
						var filePanel = Ext.getCmp('projectRegister.displayAttach');
						var fileIds = Ext.getCmp("projectRegister.attachIds");
						for (var i = 0; i < af.length; i++) {
							if (fileIds.getValue() != '') {
								fileIds.setValue(fileIds.getValue() + ',');
							}
							fileIds.setValue(fileIds.getValue() + af[i].fileId);
							Ext.DomHelper
									.append(
											filePanel.body,
											'<span><a href="#" onclick="FileAttachDetail.show('
													+ af[i].fileId
													+ ')">'
													+ af[i].fileName.replace(/\s+/g,"")+'</a>&nbsp;|&nbsp;</span>');
						}
						fileIds.originalValue = fileIds.getValue();
				},
				failure : function(form, action) {
				}
			});
		}
	},
	/**
	 * 重置
	 * @param {} formPanel
	 */
	reset:function(formPanel){
		formPanel.getForm().reset();
	},
	/**
	 * 取消
	 * @param {} window
	 */
	cancel:function(window){
		window.close();
	},
	/**
	 * 保存记录
	 */
	save:function(formPanel,window){
		if (formPanel.getForm().isValid()) {
			formPanel.getForm().submit({
				method : 'POST',
				waitMsg : '正在提交数据...',
				success : function(fp, action) {
					Ext.ux.Toast.msg('操作信息', '成功保存信息！');
					var gridPanel=Ext.getCmp('ProjectRegisterGrid');
					if(gridPanel!=null){
						gridPanel.getStore().reload();
					}
					window.close();
				},
				failure : function(fp, action) {
					Ext.MessageBox.show({
								title : '操作信息',
								msg : '信息保存出错，请联系管理员！',
								buttons : Ext.MessageBox.OK,
								icon : Ext.MessageBox.ERROR
							});
					window.close();
				}
			});
		}
	}//end of save
	
});